<html lang="zh-cn">
<head>
{% include "tdm_include_head_template.html" %}

<script type="text/javascript">
function load_city(def_city) {
  $.ajax({
    type: "GET",
    url: "/json/city/",
    async: false,
    dataType: "json",
    success: function (msg) {
      $("select#city").html('');
      $.each(msg, function(i, item) {
        $("select#city").append('<option value="'+item+'">'+item+'</option>');
      });
    }
  });
  if (def_city.length > 0) {
    $("select#city").val(def_city);
  }
}
function load_jxd(city, def_jxd) {
  var disable_jxd = [];
  $.ajax({
    type: "GET",
    url: '/json/jxd_dis/'+city,
    async: false,
    dataType: "json",
    success: function (msg) {
      $.each(msg, function(i, item) {
        disable_jxd.push(item);
      });
    }
  });
  $.ajax({
    type: "GET",
    url: '/json/jxd/'+city,
    async: false,
    dataType: "json",
    success: function (msg) {
      $("table#jxd").html('');
      $.each(msg, function(i, item) {
        var item_show = item;
        //alert(item+disable_jxd);
        if (disable_jxd.indexOf(item) > -1) {
          item_show = "<屏蔽>" + item_show;
        }
        $("table#jxd").append('<tr><td>'+item_show+'</td><td><label><input type="checkbox" name="jxd" value="'+item+'"></label></td></tr>');
      });
    }
  });
  if (def_jxd.length > 0) {
    $("select#jxd").val(def_jxd);
  }
}
$(function() {
  load_city('{{city}}');
  load_jxd($("#city").val(), '{{jxd}}');
  $("#city").change(function() {
    load_jxd($("#city").val(), '');
  });
});
</script>

</head>

<body class=" theme-blue">
{% include "tdm_include_navbar_template.html" %}

<div class="container">
  <br/>
  {% include "tdm_include_error_template.html" %}

  {% include "tdm_include_admin_page_template.html" %}

  <div class="form-context">
  <form name="city_jxd_del" class="form-horizontal" role="form" action="/tdm/admin/jxd/" method="post">
    <div class="row">
      <div class="col-sm-2">
        <select name="city" id="city" class="form-control">
          <option> </option>
        </select>
      </div>
      <div class="col-sm-4">
        <table id="jxd" class="table table-hover">
        </table>
      </div>
      <div class="col-sm-2">
        <button name="op" value="city_jxd_del" type="submit" class="btn btn-primary">删除</button>
        <button name="op" value="city_jxd_dis" type="submit" class="btn btn-primary">(解)屏蔽</button>
      </div>
    </div>
  </form>

  <hr/>

  <form role="form" name="city_jxd_add" action="/tdm/admin/jxd/" method="post">
    <div class="row">
      <div class="col-sm-2">
        <label for="new_city" class="sr-only">市地</label>
        <input name="city" type="text" class="form-control" id="new_city" placeholder="市地">
      </div>
      <div class="col-sm-4">
        <label for="new_jxd" class="sr-only">教学点</label>
        <input name="jxd" type="text" class="form-control" id="new_jxd" placeholder="教学点">
      </div>
      <div class="col-sm-2">
        <button name="op" value="city_jxd_add" type="submit" class="btn btn-primary">添加</button>
      </div>
    </div>
  </form>

  </div>

{% include "tdm_include_footer_template.html" %}
</div>
</body>
</html>